<template>
	<view class="content">
		<image class="logo" :src="blobSrc"></image>
		<view class="text-area">
			<!-- <text class="title">{{title}}</text> -->
			<button @click="uploadFile">上传文件</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				blobSrc: '',
				loading: false,
				dialogImageUrl: ''
			}
		},
		onLoad() {

		},
		methods: {
			getImageSize(src) {
				return new Promise((resolve, reject) => {
					const img = new Image()
					img.onerror = function() {
						alert('error!')
					}
					img.onload = () => {
						const width = img.width
						const height = img.height
						resolve({
							img,
							width,
							height
						})
					}
					img.src = src
				})
			},
			uploadFile() {
				this.blobSrc = ''
				uni.chooseImage({
					success: (chooseImageRes) => {
						this.loading = true
						const tempFilePaths = chooseImageRes.tempFilePaths // 上传文件的 BLOB 链接
						this.blobSrc = tempFilePaths[0]
						const tempFiles = chooseImageRes.tempFiles // 上传的文件
						console.log(chooseImageRes)

						this.getImageSize(this.blobSrc).then((res) => {
							// 1024
							// console.log('到达')
							alert('到达')
						})
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>